/**
 * Author: w景洋.
 * Time: 2016/7/6 0006
 */
angular.module('service_class.rczp', [

    ])

    .config(['$stateProvider','$urlRouterProvider',
        function($stateProvider, $urlRouterProvider) {
            $stateProvider

                .state('model.rczp-jr', {
                    url: '/rczp-jr',
                    templateUrl: service_templateprefix + "service_class/rczp-jr.html",
                    controller: 'Rczp-jrController'
                })
                .state('model.rczp-yp', {
                    url: '/rczp-yp',
                    templateUrl: service_templateprefix + "service_class/rczp-yp.html",
                    controller: 'Rczp-ypController'
                })
                .state('model.rczp-zp', {
                    url: '/rczp-zp',
                    templateUrl: service_templateprefix + "service_class/rczp-zp.html",
                    controller: 'Rczp-zpController'
                })
                //人才招聘商家信息页面
                .state('model.rczpsj', {
                    url : '/rczpsj?oId',
                    templateUrl : service_templateprefix + "service_class/rczpsj.html",
                    controller : 'RczpsjController'
                })
                .state('model.wyzp', {
                    url: '/wyzp',
                    templateUrl: service_templateprefix + "service_class/wyzp.html",
                    controller: 'WyzpController'
                })

        }])

    .controller('Rczp-jrController', ['$scope', '$state','adService', function($scope,$state,adService) {

    }])
    .controller('Rczp-ypController', ['$scope', '$state','adService', function($scope,$state,adService) {

    }])
    .controller('Rczp-zpController', ['$scope', '$state', 'RczpService',
        function($scope,$state,RczpService) {
            $scope.rczplist = RczpService.getRczpList();
            $scope.rczplist.$promise.then(function(list){
                console.log(list)
                $scope.offerlist=list;
                //console.log($scope.rczplist[0].name);
            });
            //分页
            $scope.currentPage = 1;
            $scope.pageSize = 8;


            //截取字符串
            $scope.strsplit=function(s){
                if(s==undefined){
                    return true;
                }else{
                    return s.toString().split("-");
                }
            }
            $scope.min='';
            $scope.max='';
            $scope.name='';
            $scope.getPagingSearchList=function(){
                RczpService.getPagingSearchList($scope.adr,$scope.name,$scope.min,$scope.max).$promise.then(function(data){
                    $scope.offerlist=[];
                    $scope.offerlist=data;
                })
            }
            //adr
            $scope.aplitadr=function(adr){
                $scope.getPagingSearchList();
            }
            //jobNumber
            $scope.aplitjobNumber=function(jobNumber){
                //console.log(jobNumber);
                //var str=$scope.strsplit(jobNumber);
                //$scope.jobNumberMin=str[0];
                //$scope.jobNumberMmax=str[1];
                if(jobNumber==''){
                    $scope.name='';
                }
                else{
                    $scope.name='jobNumber';
                }
                $scope.jobOther="";
                $scope.searchJob="";
                var str=$scope.strsplit(jobNumber);
                $scope.min=str[0];
                $scope.max=str[1];
                $scope.getPagingSearchList();
            }
            //$scope.filterJobNumber = function(val) {
            //    if($scope.jobNumberMin==undefined || $scope.jobNumberMin==''){
            //        return val;
            //    }
            //    return (val.jobNumber >=  $scope.jobNumberMin && val.jobNumber  <= $scope.jobNumberMmax);
            //};
            //jobOther
            $scope.aplitjobOther=function(jobOther){
                if(jobOther==''){
                    $scope.name='';
                }
                else{
                    $scope.name='jobOther';
                }
                $scope.jobNumber="";
                $scope.searchJob="";
                var str=$scope.strsplit(jobOther);
                $scope.min=str[0];
                $scope.max=str[1];
                $scope.getPagingSearchList();
            }
            //searchJob
            $scope.aplitsearchjob=function(searchJob){
                $scope.getPagingSearchList();
            }
        }])
    //我要招聘页面
    .controller('WyzpController', ['$scope', '$state', 'WyzpService', 'fileUpload',
        function($scope,$state,WyzpService,fileUpload) {
            $scope.zpinfo = "";
            $scope.putZpInfo=function(){
                $scope.success_func = function(){//提交成功回调函数
                    $state.go("rczp-zp");
                }
                $scope.error_func = function(data){//提交失败回调函数
                    alert(data.data.reason);
                }
                WyzpService.putZpInfo($scope.zpinfo,$scope.success_func,$scope.error_func);
            };
            $scope.uploadFile = function(){
                if($scope.myFile==undefined){
                    alert("请选择图片！");
                    return;
                }
                var file = $scope.myFile;
                fileUpload.uploadFileToUrl(file).then(function(data){
                    $scope.zpinfo.store_photo = data;
                    if(data!=undefined){
                        return;
                    }
                });
            };
        }])
    //我要应聘页面
    .controller('WyypController', ['$scope', '$state', 'WyypService',
        function($scope,$state,WyypService) {
            $scope.ypinfo = "";
            $scope.putYpInfo=function(){
                $scope.success_func = function(){//提交成功回调函数
                    $state.go("rczp-yp");
                }
                $scope.error_func = function(data){//提交失败回调函数
                    alert(data.data.reason);
                }
                WyypService.putYpInfo($scope.ypinfo,$scope.success_func,$scope.error_func);
            };
        }])
    //人才招聘商家信息页面
    .controller('RczpsjController', ['$scope', '$state', 'RczpsjService','$stateParams',
        function($scope,$state,RczpsjService,$stateParams) {
            $scope.rczpsjlist = RczpsjService.getRczpsjList($stateParams.oId);
            $scope.rczpsjlist.$promise.then(function(list){
                //console.log($scope.rczplist[0].name);
            });
        }])
